import {
	api
} from './api.js'
async function request(method, url, data) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: api.base + url,
			data,
			method,
			header: {
				'content-type': "application/json",
				'authorization': uni.getStorageSync('token')
			},
			dataType: 'json',
			success: (res) => {
				if (res.data.code != 200) {
					console.log(res);
				}
				resolve(res.data)
			},
			fail(err) {
				uni.showToast({
					title: '网络请求失败',
					icon: 'error'
				})
				console.log(err);
			}
		})
	})
}
export default {
	async get(url, data) {
		return await request('GET', url, data)
	},
	async post(url, data) {
		return await request('POST', url, data)
	},
	async put(url, data) {
		return await request('PUT', url, data)
	},
}